package com.qfedu.channel.controller;

import com.qfedu.channel.domain.Channel;
import com.qfedu.channel.service.IChannelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-03-01
 */
@RestController
@RequestMapping("/qf/channel")
public class ChannelController extends BaseController {

    @Autowired
    IChannelService channelService;

    /**
     * @return
     * @RequiresPermissions("qf:channel:list") 查询的权限  在前端界面添加权限
     * startPage（）. 公共的参数 比如分页这类
     */
    @RequiresPermissions("qf:channel:list")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<Channel> list = channelService.selectChannelList();
        return getDataTable(list);
    }


    /**
     * 添加渠道
     */
    @RequiresPermissions("qf:channel:create")
    @PostMapping
    public AjaxResult createChannel(@RequestBody Channel channel) {
        return channelService.createChannel(channel);
    }

    /**
     * 删除渠道
     */
    @RequiresPermissions("qf:channel:remove")
    @DeleteMapping("/{channelIds}")
    public AjaxResult remove(@PathVariable Long[] channelIds) {

        return channelService.deleteUserByIds(channelIds);
    }


    /**
     * 修改渠道
     *
     * @param channel
     * @return
     */
    @RequiresPermissions("qf:channel:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Channel channel) {
        return channelService.edit(channel);
    }


    //@RequiresPermissions("qf:channel:editById")
//    @GetMapping("/{channelId}")
    @GetMapping("/{channelId}")
    public Channel editById(@PathVariable Integer channelId) {
        return channelService.editById(channelId);
    }


}
